Become a Pro / website · becomeapro.ai / src / app / api / auth / [...path] / route.ts
| 1 | import { createResourceAuth, resourceAuth, resourceAuthSettings } from "@/lib/d1-auth"; |
| 2 | import { browserSignIn } from "@/lib/provider-sign-in"; |
| 3 | |
| 4 | export const dynamic = "force-dynamic"; |
| 5 | |
| 6 | export function GET(request: Request) { |
| 7 | const path = new URL(request.url).pathname; |
| 8 | return path === "/api/auth/get-session" ? resourceAuth().handler(request) : new Response(null, { status: 404 }); |
| 9 | } |
| 10 | |
| 11 | export function POST(request: Request) { |
| 12 | const path = new URL(request.url).pathname; |
| 13 | if (path === "/api/auth/sign-out") return resourceAuth().handler(request); |
| 14 | if (path === "/api/auth/identity/challenge" || path === "/api/auth/identity") { |
| 15 | const settings = resourceAuthSettings(); |
| 16 | const auth = createResourceAuth(settings.db, settings.origin, settings.secret, settings.providers); |
| 17 | return browserSignIn(request, { ...settings, auth }); |
| 18 | } |
| 19 | return new Response(null, { status: 404 }); |
| 20 | } |